package com.s3.khospitalds.controller;

import com.s3.khospitalds.common.R;
import com.s3.khospitalds.common.R;
import com.s3.khospitalds.common.ResponseEntity;
import com.s3.khospitalds.entity.Doctor;
import com.s3.khospitalds.entity.DoctorResignInfo;
import com.s3.khospitalds.service.impl.DoctorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 想要告诉你
 * @CreateTime: 2025/2/19 10:41
 * @Description:
 * @Version: 1.0
 */

@RestController
@CrossOrigin(origins = "*")
public class DoctorController {
    @Autowired
    private DoctorServiceImpl doctorService;

    @GetMapping("/getAllDoctor")
    public R getAllDoctor() {
        return new R().addData("list",doctorService.getDoctorResignInfo());
    }
    // 获取医生信息
    @RequestMapping("/getDoctor")
    public ResponseEntity getDoctor(Integer pageNum, Integer pageSize, String search){
        pageNum = pageNum == null ? 1 : pageNum;
        pageSize = pageSize == null ? 10 : pageSize;
        search = search == null ? "" : search;
        return doctorService.getDoctor(pageNum,pageSize,search);
    }

    // 获取离职医生信息
    @RequestMapping("/getResignDoctor")
    public ResponseEntity getResignDoctor(){
        return doctorService.getResignDoctor();
    }

    // 插入医生信息
    @PostMapping("/insertDoctor")
    public R insertDoctor(@RequestBody Doctor doctor){
        return new R().addData("doctor",doctorService.insertDoctor(doctor));
    }

    // 更新医生信息
    @PostMapping("/updateDoctor")
    public R updateDoctor(@RequestBody Doctor doctor){
        return new R().addData("doctor",doctorService.updateDoctor(doctor));
    }

    // 删除医生信息
    @PostMapping("/deleteDoctor")
    public R deleteDoctor(@RequestBody DoctorResignInfo doctorResignInfo){
        System.out.println("doctorResignInfo = " + doctorResignInfo);
        return new R().addData("doctor",doctorService.deleteDoctor(doctorResignInfo));
    }
}
